package com.ml.carManager.ui.diver.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import androidx.appcompat.widget.LinearLayoutCompat;

import com.hjq.toast.ToastUtils;
import com.ml.carManager.R;
import com.ml.carManager.utils.auth.AuthManager;

import java.util.List;

import butterknife.BindView;
import custom.base.entity.order.OrderList;
import custom.base.ui.adapter.BaseRecyclerAdapter;
import custom.base.ui.adapter.BaseViewHolder;
import custom.base.utils.AppUtils;
import custom.base.utils.ClipboardUtils;

/**
 * Created by thl on 2016-03-30.
 */
public class OrderAdapter extends BaseRecyclerAdapter<OrderList> {
    private Context context;

    AppUtils.ScreenModel screenModel;
    int size = 0;

    public OrderAdapter(List<OrderList> list) {
        super(list);
        this.screenModel = screenModel;

    }

    @Override
    public BaseViewHolder onCreateContentViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_order_list, parent, false);
        context = parent.getContext();
        return new MyHolder(view);
    }

    public class MyHolder extends BaseViewHolder<OrderList> {
        @BindView(R.id.view_order_list_no)
        TextView tvNo;
        @BindView(R.id.view_order_list_source)
        TextView tvSource;
        @BindView(R.id.view_order_list_target)
        TextView tvTarget;
        @BindView(R.id.view_order_list_contract)
        TextView tvContract;
        @BindView(R.id.view_order_list_config)
        TextView tvConfig;
        @BindView(R.id.view_order_list_status)
        TextView tvStatus;
        @BindView(R.id.view_order_list_no_bg)
        LinearLayoutCompat llNoBg;
        @BindView(R.id.view_order_list_content)
        LinearLayoutCompat llContent;


        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void showView(int position, final OrderList item) {
            tvNo.setText(item.getNo());
            tvSource.setText(item.getSource());
            tvTarget.setText(item.getTarget());
            tvStatus.setText(AuthManager.getInstance().getDictLabel("order_status", item.getStatus()));
            if (item.getStatus() != null && item.getStatus() == 0) {
                tvStatus.setBackgroundResource(R.drawable.corner_orange_color_bg_2);
                llNoBg.setBackgroundResource(R.drawable.corner_orange_color_bg_top20);
            } else {
                tvStatus.setBackgroundResource(R.drawable.corner_main_color_bg_2);
                llNoBg.setBackgroundResource(R.drawable.corner_main_color_bg_top20);
            }
            tvContract.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });

            tvConfig.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
            if (llContent.getChildCount() > 0) {
                llContent.removeAllViews();
            }

            if (item.getContent() != null) {
                for (int i = 0; i < item.getContent().size(); i++) {
                    View contentView = LayoutInflater.from(itemView.getContext()).inflate(R.layout.view_order_list_content, null, false);
                    TextView textView = contentView.findViewById(R.id.view_order_list_content_text);
                    textView.setText(item.getContent().get(i).getName() + " " + item.getContent().get(i).getNum() + " " + item.getContent().get(i).getUnit());
                    llContent.addView(contentView);
                }
            }

            llNoBg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ClipboardUtils.clipToBorad(itemView.getContext(), item.getNo());
                    ToastUtils.show("已复制物流号");
                }
            });
        }
    }

}
